# 函数
# 定义一个求和函数
# def func_sum(begin, end):
#     thesum = 0
#     for i in range(begin, end + 1):
#         thesum += i
#     print(thesum)

#调用函数 1-100的和
# func_sum(1, 100)
#
# # 先定义一个函数
# def test():
#     print('hhh')
#     print('kkk')
# test()

# def test(a, b, c):
#     print(a, b, c)
#     print(a + b + c)
#
# test(10, 20, 30)
#
# def add(a, b):
#     print(a + b)
#
# add(1,2)
# add(1.1, 2.2)
# add("hello", "yss")

# 函数返回值
# def func(a, b):
#     t = a + b
#     return t
#
# ret = func(99, 88)
# print(ret)

# 可以有多个return 语句, 搭配分支语句/循环语句使用
# def test():
#     a = 10
#     if a == 10:
#         return True
#     else:
#         return False
#
# ret = test()
# print(ret)

# 一次返回多个值
# def test1():
#     return 10, 20, 30, 40
#
# a, b, c, d = test1()
# print(a, b, c, d)
# print(a + b + c+ d)
# print(a)
# print(b)
# print(c)
# print(d)

# 全局变量修改-global
# g = 10
# def test2():
#     global  g # 声明是全局的, 接下来修改这个全局变量
#     g = 20
#
#
# test2()
# print(g)

# 只有函数和类才会区分作用域，if for while等语句没有影响
# for i in range(1, 11):
#     print(i)
#
# print(i)
#
# if True:
#     x = 100
# print(x)

# 函数的嵌套调用和链式调用
def test2():
    print(222)

def test1():
    print(111)
    test2()

test1()

def add2(a):
    return a

def add1(a, b):
    return a + b

print(add2(add1(10, 20)))